<template>
	<view>
		<van-uploader :file-list="fileList" @after-read="afterRead" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList: [],
			}
		},
		methods: {
			afterRead(event) {
				console.log(event.detail);
				const {
					file
				} = event.detail;
				console.log(file);
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				uni.uploadFile({
					url: 'http://112.74.185.144:8000/api/common/uploadfile', // 仅为示例，非真实的接口地址
					filePath: file.url,
					name: 'file',
					formData: {
						'file': file.url
					},
					success(res) {
						// 上传完成需要更新 fileList
						console.log(res);
						const {
							fileList = []
						} = this.data;
						fileList.push({
							...file,
							url: res.data
						});
						this.setData({
							fileList
						});
					},
				});
			}
		}
	}
</script>

<style>

</style>
